// VBConversions Note: VB project level imports
using System.Collections.Generic;
using System;
using System.Linq;
using System.Drawing;
using System.Diagnostics;
using Microsoft.VisualBasic;
using System.Xml.Linq;
using Microsoft.VisualBasic.Compatibility;
using System.Windows.Forms;
using System.Collections;
using System.Data;
// End of VB project level imports

using System.Runtime.InteropServices;

namespace 喷码数据生成工具
{
	sealed class SupportWords
	{
		
		//调用一个窗口的窗口函数，将一条消息发给那个窗口。除非消息处理完毕，否则该函数不会返回。SendMessageBynum， SendMessageByString是该函数的“类型安全”声明形式
		[DllImport("user32", EntryPoint = "SendMessage", SetLastError = false, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]public static  extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, ref IntPtr lParam);
		public const int WM_SETREDRAW = 0xB;
		//取得当前活动键盘布局的名称
		[DllImport("user32", EntryPoint = "GetKeyboardLayoutName", SetLastError = false, 
		CharSet = CharSet.Auto, ExactSpelling = false, 
		CallingConvention = CallingConvention.StdCall)]public static  extern int GetKeyboardLayoutName(string pwszKLID);
		//取得一个句柄，描述指定应用程序的键盘布局
		[DllImport("user32", EntryPoint = "GetKeyboardLayout", SetLastError = false, 
		CharSet = CharSet.Auto, ExactSpelling = false, 
		CallingConvention = CallingConvention.StdCall)]public static  extern int GetKeyboardLayout(int dwLayout);
		[DllImport("TLBINF32", EntryPoint = "loword", SetLastError = false, 
		CharSet = CharSet.Auto, ExactSpelling = false, 
		CallingConvention = CallingConvention.StdCall)]public static  extern short loword(int DWord);
		
		public struct IsInCheckCode
		{
			public int StartCode;
			public int EndCode;
			public IsInCheckCode(int _StartCode, int _EndCode)
			{
				this.StartCode = _StartCode;
				this.EndCode = _EndCode;
			}
		}
		public enum EnumSplitMode
		{
			/// <summary>
			/// 无分开模式
			/// </summary>
			/// <remarks></remarks>
			NoneSplit = 0,
			/// <summary>
			/// 多意分隔模式
			/// </summary>
			/// <remarks></remarks>
			SplitMode = 1,
			ThreeSplitMode = 2
		}
		public struct SplitModeKeyWord
		{
			public string StartWord1;
			public string StartWord2;
			public string StartWord3;
			public string EndWord;
			public EnumSplitMode WordMode;
			public SplitModeKeyWord(string Word, string _EndWord)
			{
				this.WordMode = EnumSplitMode.NoneSplit;
				this.StartWord1 = Word;
				this.EndWord = _EndWord;
			}
			public SplitModeKeyWord(string Word1, string Word2, string _EndWord)
			{
				this.WordMode = EnumSplitMode.SplitMode;
				this.StartWord1 = Word1;
				this.StartWord2 = Word2;
				this.EndWord = _EndWord;
			}
			public SplitModeKeyWord(string Word1, string Word2, string Word3, string _EndWord)
			{
				this.WordMode = EnumSplitMode.ThreeSplitMode;
				this.StartWord1 = Word1;
				this.StartWord2 = Word2;
				this.EndWord = _EndWord;
				this.StartWord3 = Word3;
			}
			public override string ToString()
			{
				if (this.WordMode == EnumSplitMode.NoneSplit)
				{
					return this.StartWord1 + "," + EndWord;
				}
				else if (this.WordMode == EnumSplitMode.SplitMode)
				{
					return this.StartWord1 + "," + this.StartWord2 + "," + this.EndWord;
				}
				else
				{
					return this.StartWord1 + "," + this.StartWord2 + "," + this.StartWord3 + "," + this.EndWord;
				}
			}
		}
		public struct StFunWord
		{
			public string FunName;
			public int ParamCount;
			public StFunWord(string _FunName, int _ParamCount)
			{
				this.FunName = _FunName;
				this.ParamCount = _ParamCount;
			}
			public StFunWord(string _FunName)
			{
				this.FunName = _FunName;
				this.ParamCount = -1;
			}
		}
		public struct VbsKeyCode
		{
			public List<SplitModeKeyWord> SplitWord;
			public List<StFunWord> FunCode;
			public object SplitWordTag;
			public void AddSplitWord(string Word, string _EndWord)
			{
				SplitModeKeyWord tmpItem = new SplitModeKeyWord();
				if (SplitWord == null)
				{
					SplitWord = new List<SplitModeKeyWord>();
				}
				tmpItem.WordMode = EnumSplitMode.NoneSplit;
				tmpItem.StartWord1 = Word;
				tmpItem.EndWord = _EndWord;
				this.SplitWord.Add(tmpItem);
			}
			public void AddSplitWord(string Word1, string Word2, string _EndWord)
			{
				SplitModeKeyWord tmpItem = new SplitModeKeyWord();
				if (SplitWord == null)
				{
					SplitWord = new List<SplitModeKeyWord>();
				}
				tmpItem.WordMode = EnumSplitMode.SplitMode;
				tmpItem.StartWord1 = Word1;
				tmpItem.StartWord2 = Word2;
				tmpItem.EndWord = _EndWord;
				this.SplitWord.Add(tmpItem);
			}
			public void AddSplitWord(string Word1, string Word2, string Word3, string _EndWord)
			{
				SplitModeKeyWord tmpItem = new SplitModeKeyWord();
				if (SplitWord == null)
				{
					SplitWord = new List<SplitModeKeyWord>();
				}
				tmpItem.WordMode = EnumSplitMode.ThreeSplitMode;
				tmpItem.StartWord1 = Word1;
				tmpItem.StartWord2 = Word2;
				tmpItem.EndWord = _EndWord;
				tmpItem.StartWord3 = Word3;
				this.SplitWord.Add(tmpItem);
			}
			public void AddFunCode(string _FunName, int _ParamCount)
			{
				StFunWord tmpItem = new StFunWord();
				if (FunCode == null)
				{
					FunCode = new List<StFunWord>();
				}
				tmpItem.FunName = _FunName;
				tmpItem.ParamCount = _ParamCount;
				this.FunCode.Add(tmpItem);
			}
			public void AddFunCode(string _FunName)
			{
				if (FunCode == null)
				{
					FunCode = new List<StFunWord>();
				}
				if (_FunName.IndexOf(",") < 0)
				{
					StFunWord tmpItem = new StFunWord(_FunName);
					this.FunCode.Add(tmpItem);
				}
				else
				{
					string[] a = _FunName.Split(',');
					for (var i = 0; i <= a.Length - 1; i++)
					{
						if (!string.IsNullOrEmpty(a[(int) i]))
						{
							StFunWord tmpItem = new StFunWord(a[(int) i]);
							this.FunCode.Add(tmpItem);
						}
					}
				}
			}
			public string get_GetSplitWordString(char SplitChar)
			{
				//On Error Resume Next VBConversions Warning: On Error Resume Next not supported in C#
				string Result = Constants.vbNullString;
				for (var i = 0; i <= this.SplitWord.Count - 1; i++)
				{
					if (string.IsNullOrEmpty(Result))
					{
						Result = this.SplitWord[i].ToString();
					}
					else
					{
						Result += SplitChar + this.SplitWord[i].ToString();
					}
				}
				return Result;
			}
			public string get_GetFunCodeString(char SplitChar)
			{
				//On Error Resume Next VBConversions Warning: On Error Resume Next not supported in C#
				string Result = Constants.vbNullString;
				for (var i = 0; i <= this.FunCode.Count - 1; i++)
				{
					if (string.IsNullOrEmpty(Result))
					{
						Result = this.FunCode[i].ToString();
					}
					else
					{
						Result += SplitChar + this.FunCode[i].ToString();
					}
				}
				return Result;
			}
		}
		/// <summary>
		/// 停止重绘
		/// </summary>
		/// <param name="Handle"></param>
		/// <remarks></remarks>
		public static void DisablePaint(IntPtr Handle)
		{
			SendMessage(Handle, WM_SETREDRAW, 0, ref IntPtr.Zero);
		}
		/// <summary>
		/// 允许重绘
		/// </summary>
		/// <param name="Handle"></param>
		/// <remarks></remarks>
		public static void AllowPaint(IntPtr Handle)
		{
			SendMessage(Handle, WM_SETREDRAW, 1, ref IntPtr.Zero);
		}
		public static bool IsExistsCode(int Code, List<IsInCheckCode> CodeList)
		{
			if (CodeList.Count > 0)
			{
				for (var i = 0; i <= CodeList.Count - 1; i++)
				{
					if (Code >= CodeList[System.Convert.ToInt32(i)].StartCode && Code <= CodeList[System.Convert.ToInt32(i)].EndCode)
					{
						return true;
					}
				}
				return false;
			}
			else
			{
				return false;
			}
		}
	}
	
}
